public class Main {
    public static void main(String[] args) {
        System.out.println(new Solution().maxProfit(new int[]{7,1,5,3,6,4}));
        System.out.println(new Solution().maxProfit(new int[]{1,2,3,4,5}));
        System.out.println(new Solution().maxProfit(new int[]{7,6,4,3,1}));
    }
}

class Solution {
    public int maxProfit(int[] prices) {
        int inPrice = prices[0];
        int totalProfit = 0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i] > inPrice) {
                totalProfit += prices[i] - inPrice;
            }
            inPrice = prices[i];
        }
        return totalProfit;
    }
}